#include <iostream>
#include <thread>
#include <future>

int Add(int num1, int num2, std::promise<int>& prom)
{
    prom.set_value(num1 + num2);
    return num1 + num2;
}

int main()
{
    std::promise<int> prom;
    //通过std::promise的get_future()函数与fu绑定
    std::future<int> fu = prom.get_future();

    //将函数Add及对象prom放在线程里面执行
    std::thread thr(Add, 10, 20, std::ref(prom));
    int res = fu.get();
    std::cout << "sum: " << res << std::endl;
    thr.join();

    return 0;
}